package internal

import (
	"go.uber.org/zap"
	"gogogo-server/engine/cororpc"
	"gogogo-server/engine/network/codec/msgpack"
	"gogogo-server/protocol"
)

func OnNewAgent(args []any) {
	a := args[0].(cororpc.IGateAgent)
	hw := &protocol.HelloWorld{
		Data: "HelloWorld",
	}
	// 发送消息
	if err := a.SendMsg(protocol.MsgEventHelloWorld, uint16(39), hw); err != nil {
		zap.S().Fatalf("发送消息失败:%s", err)
	}
}

func OnCloseAgent(args []any) {
	a := args[0].(cororpc.IGateAgent)
	zap.S().Infof("连接:%s 关闭", a.RemoteAddr())
}

func OnHelloWorld(args []any) {
	seqId, msg := msgpack.UnwrapMessage[protocol.HelloWorld](args[0])
	zap.S().Infof("收到服务器返回:seq:%v, %v", seqId, msg)
}
